//
// Created on 2025/6/9.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef FFTW_TEST1_QUEUE_H
#define FFTW_TEST1_QUEUE_H

#ifndef MESSAGE_QUEUE_H
#define MESSAGE_QUEUE_H

#include <pthread.h>
#include <stddef.h>

// 消息类型定义
typedef struct Message {
    int type;
    void* data;
    size_t data_size;
    struct Message* next;
} Message;

// 消息队列结构
typedef struct {
    Message* head;
    Message* tail;
    pthread_mutex_t lock;
    pthread_cond_t cond;
    int shutdown;
} MessageQueue;

// 初始化消息队列
void mq_init(MessageQueue* queue);

// 销毁消息队列
void mq_destroy(MessageQueue* queue);

// 发送消息（异步）
void mq_send(MessageQueue* queue, int type, void* data, size_t data_size);

// 接收消息（阻塞）
Message* mq_receive(MessageQueue* queue);

// 非阻塞接收消息
Message* mq_try_receive(MessageQueue* queue);

// 释放消息内存
void mq_free_message(Message* msg);

#endif    

#endif //FFTW_TEST1_QUEUE_H
